﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Helper
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        #region 服务方法
        /// <summary>
        /// 根据字段生成属性
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        public static string DoGetProp(string field)
        {

            string rs = field.Trim().Substring(0, 1).ToUpper() + field.Trim().Substring(1);
            if (rs.StartsWith("_"))
            {
                rs = DoGetProp(rs.Substring(1));
            }
            if (field.Equals(rs, StringComparison.Ordinal))
            {
                rs = field + "Prop";
            }

            return rs;
        }

        #endregion

        private void Btn01_Click(object sender, RoutedEventArgs e)
        {
            TextRange textRange = new TextRange(rtb01.Document.ContentStart, rtb01.Document.ContentEnd);
            string[] strs = { Environment.NewLine + "" };
            string[] rs = textRange.Text.Split(strs, StringSplitOptions.RemoveEmptyEntries);

            rtb02.Document.Blocks.Clear();
            foreach (var item in rs)
            {
                string[] fs = item.Split(',');
                try
                {

                    fs = item.Split(',');
                    if (string.IsNullOrEmpty(fs[1]))
                    {
                        continue;
                    }
                }
                catch (Exception exp)
                {

                    MessageBox.Show(exp.Message);
                    break;
                }


                rtb02.AppendText($"/// <summary>");
                rtb02.AppendText($"{Environment.NewLine}");
                rtb02.AppendText($"///{fs[1].Trim()}{Environment.NewLine}");
                rtb02.AppendText($"/// </summary>{Environment.NewLine}");
                rtb02.AppendText($"private string {fs[0]};{Environment.NewLine}");
                rtb02.AppendText($"/// <summary>{Environment.NewLine}");
                rtb02.AppendText($"///读写属性{fs[1].Trim()}{Environment.NewLine}");
                rtb02.AppendText($"/// </summary>{Environment.NewLine}");
                // public string DomClass { get => domClass; set => domClass = value; }
                rtb02.AppendText($"public string {DoGetProp(fs[0])} {{ get => {DoGetProp(fs[0])}; set => {DoGetProp(fs[0])} = value; }}{Environment.NewLine}");
            }



        }
    }
}
